package mashuaiproject.mashuaiproject.mapper;


import mashuaiproject.mashuaiproject.model.Users;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface UserMapper {

    @Insert("insert into users (name,account_id,token,gmt_create,gmt_modified,avatarUrl)" +
            "values(#{name},#{account_id},#{token},#{gmt_create},#{gmt_modified},#{avatarUrl})")
    void insertUser(Users users);//如果新用户登录报错，就删除这个avatarUrl字段
    @Select("select *from users where account_id=#{account_id}")
    Users checkUser(@Param("account_id") String account_id);

    @Select("select *from users where token=#{token}")
    Users findByToken(@Param("token") String token);

    //根据文章的creator 对应user的id
    @Select("select *from users where id=#{creator}")
    Users findByUser(@Param("creator") int id);

    @Insert("insert into users (name,account_id,token,gmt_create,gmt_modified,avatarUrl,password)" +
            "values(#{name},#{account_id},#{token},#{gmt_create},#{gmt_modified},#{avatarUrl},#{password})")
    void insertUser2(Users users);

    @Select("select  COUNT(1) from users where account_id=#{account_id} or name=#{name}")
    int checkUser2(@Param("account_id") String account_id, @Param("name") String name);

    @Select("select password from users where account_id=#{account_id}")
    String findUsersPass(@Param("account_id") String loginEmail);

    @Select("select token from users where account_id=#{account_id}")
    String findUserToken(String loginEmail);

    @Update("update users set avatarUrl=#{avatarUrl} where id=#{id}")
    void updateAvatarul(@Param("id") int id, @Param("avatarUrl") String filename);

    @Update("update users set name=#{name} where id=#{id}")
    void updateName(@Param("id") Integer id, @Param("name") String modifiedName);
    @Select("select count(1) from users where name=#{name}")
    int checkName(@Param("name") String modifiedName);
    @Update("update users set signature=#{signature} where id=#{id}")
    int upateSignature(@Param("id") Integer id, @Param("signature") String signature);

    @Update("update users set fensi_count=fensi_count-1 where id=#{id}")
    int delFenSi(@Param("id") Integer delMyGuanzhu);
    @Insert("insert into selfxunzhang (user_id,xunzhang_id) values(#{id},1)")
    int insertSelfXunzhang(@Param("id") Integer id);
    @Update("update users set chenwei=#{chenwei} where id=#{id}")
    int upateChenWei(@Param("id") Integer id,@Param("chenwei") String chenwei);

    @Select("select `leave` from users where id=#{id}")
    Integer selectByLeave(Integer id);
    @Select("select exp from users where id=#{id}")
    Integer selectByExp(Integer id);
    @Select("select jifen from users where id=#{id}")
    Integer selectByJifen(Integer id);
    @Select("select weiwang from users where id=#{id}")
    Integer selectByWeiwang(Integer id);

    @Update("update users set  `leave`=#{leave} where id=#{id} ")
    Integer updateLeave(@Param("id") Integer id, @Param("leave") Integer leave);
    @Select("select  *from  users group by count_ranking  desc limit 0,10")
    List<Users> selecAllUser();
    @Update("update users set count_ranking =#{count} where id=#{id} ")
    Integer updateRanking(@Param("id") Integer id,@Param("count")Integer count);
    @Select("select  *from  users")
    List<Users> selecAllUser2();
    @Select("select  *from  users group by count_ranking desc limit 0,10")
    List<Users> selecAllUser3();
    @Update("update users set week_ranking =#{i} where id=#{id} ")
    Integer updateWeekRenking(@Param("id") Integer id, @Param("i") int i);
    @Select("select *from users order by gmt_create asc ")
    List<Users> selecAllUser4();
    @Select("select  count(1) from users  ")
    Integer selectCountUsers();
}
